﻿

var g_str_type_1 = "";
var g_str_type_2 = "";
var g_str_type_3 = ""; 
var g_str_sex = "0"; 
var g_bool_init_finish = false;


//-------------页面初始化--------------
function initPage()
{
    GetListType_1();  //查找一级类
}

//-------------查找分类--------------
function GetListType_1()
{  
	PostToPHP(__GetListType_1_Callback, "info", "query_type_1", ""); 
}
function __GetListType_1_Callback(text)
{   
	//alert(text);
	var jsonObj = String2JSON(text);
	var ds = GetDataSet(jsonObj);

	if(ds && ds[0])
	{
        FillSelectObj("type_1", ds[0]);
		on_select_change_type1();
	}
}
function on_select_change_type1()
{  
	tmpTypeVal = $('type_1').value;      //当前选择类别
	var data = "&typeName=" + tmpTypeVal;
	PostToPHP(__on_select_change_type1_callback, "info", "query_type_2", data); 
}
function __on_select_change_type1_callback(text)
{
	//alert(text);
	var jsonObj = String2JSON(text);
	var ds = GetDataSet(jsonObj);
	if(ds && ds[0])
	{
        FillSelectObj("type_2", ds[0]);
		on_select_change_type2();
	}
}

function on_select_change_type2()
{  
	tmpTypeVal_1 = $('type_1').value;      	//当前选择类别1
	tmpTypeVal = $('type_2').value;      	//当前选择类别2
	var data = "&typeName_1=" + tmpTypeVal_1;
	data += "&typeName=" + tmpTypeVal;
	PostToPHP(__on_select_change_type2_callback, "info", "query_type_3", data); 
}
function __on_select_change_type2_callback(text)
{
	//alert(text);
	var jsonObj = String2JSON(text);
	var ds = GetDataSet(jsonObj);
	if(ds && ds[0])
	{
        FillSelectObj("type_3", ds[0]);	
		g_bool_init_finish = true;		//初始化成功
	}
} 

//-------------查询-----------
function on_query()
{ 
	if(!g_bool_init_finish)
		return;
		
	g_str_type_1 = $("type_1").value;       //当前二级类
	g_str_type_2 = $("type_2").value;       //当前二级类
	g_str_type_3 = $("type_3").value;   	//当前三级类
	g_str_sex = $("select_gender").value;   //当前选择查询的性别
	
	CleanConfig(); //清空配置 
	/*
   if(g_str_type_2 == "music")
	{
		AddItemConfig("filepath", 100, "goods_id", GetSwfFileRootPath(), "_0_0.mp3", "");
		AddItemConfig("", 3);
	}
   else
	{ 
		AddItemConfig("filepath", 101, "goods_id", GetSwfFileRootPath(), "_0."+GetFilePostfix(), "sex");
		AddItemConfig("filepath", 101, "goods_id", GetSwfFileRootPath(), "_1."+GetFilePostfix(), "sex");
	}
	
	if (g_str_type_2 == "shoes" || g_str_type_2 == "skin" || g_str_type_2 == "bag" || g_str_type_2 == "bracelet")  //鞋子和肤色多一个文件
		{AddItemConfig("filepath", 101, "goods_id", GetSwfFileRootPath(), "_2."+GetFilePostfix(), "sex");}
   else {AddItemConfig("", 3);}     
	*/   
	 
	AddItemConfig("goods_id", 0);
	AddItemConfig("sex", 98, JudgeIsSexTextFunc);
	AddItemConfig("level", 0);   
	
	AddItemConfig("type_3", 0);
	AddItemConfig("goods_name", 0);
	AddItemConfig("goods_name_view", 0);
	
	AddItemConfig("gold", 0);
	AddItemConfig("money", 0);
	AddItemConfig("charm", 0);
	
	AddItemConfig("z_1", 0);
	AddItemConfig("z_2", 0);
	
	AddItemConfig("is_sell", 98, JudgeIsSellTextFunc);
	AddItemConfig("is_new", 98, JudgeIsNewTextFunc);
	
	AddItemConfig("remark", 0);
	
	AddItemConfig("goods_id", 99, "../edit/goods_edit.html?type_1="+ g_str_type_1 +"&type_2="+ g_str_type_2 +"&sex="+ g_str_sex +"&goods_id=", "编辑");
	AddItemConfig("goods_id", 2, "deleteFunc", "删除");
	AddItemConfig("goods_id", 2, "editIsSellFunc", "设置可售"); 
	AddItemConfig("goods_id", 2, "editIsNewFunc", "设置新旧");  
	
	var _data_1 = "&type_1=" + g_str_type_1;  
		_data_1 += "&type_2=" + g_str_type_2;  
		_data_1 += "&type_3=" + g_str_type_3; 
		_data_1 += "&sex=" + g_str_sex;   
	
	SetPagingConfig("paging", "get_goods_total", _data_1, 
					"paging", "get_goods_list", _data_1);
					
	PagingInit(GetDefaultPageCount(), "tbody_query", "div_paging");            
}

//--删除
function deleteFunc(index, id)
{ 
	alert("不允许删除");
	return;
	if(confirm("是否删除?") == false) return;
	
	var data = "&goods_id=" + id; 
	PostToPHP(__deleteFuncCallback, "info", "delete_goods", data);
}
function __deleteFuncCallback(text)
{
	// alert(text); 
	var jsonObj = String2JSON(text);            
	ShowReturnMsg(jsonObj, RePaging);
}

function JudgeIsSexTextFunc(index, val) //男女 0:女， 1:男
{
	return val == 0 ? "女" : "男";
}
function JudgeIsSellTextFunc(index, val) //是否可售(0为不可售 1:可售
{
	return val == 0 ? "停售" : "在售";
}
function JudgeIsNewTextFunc(index, val) //是否新品(0为新 1:旧)
{
	return val == 0 ? "新" : "旧";
}

//---设置新旧
function editIsNewFunc(index, id)
{ 
	//if(confirm("是否设置新旧?") == false) return;	
	var data = "&goods_id=" + id; 
	PostToPHP(__editNoSellFuncCallback, "info", "set_goods_is_new", data);
}
//---设置可售
function editIsSellFunc(index, id)
{ 
	//if(confirm("是否设置可售?") == false) return;	
	var data = "&goods_id=" + id; 
	PostToPHP(__editNoSellFuncCallback, "info", "set_goods_is_sell", data);
} 
function __editNoSellFuncCallback(text)
{
	// alert(text); 
	var jsonObj = String2JSON(text);            
	ShowReturnMsg(jsonObj, RePaging);
}
